package za.co.smartmi.util;

import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import za.co.smartmi.form.ClientSearchForm;
import za.co.smartmi.model.Client;
import za.co.smartmi.server.model.ActiveInactiveType;

/**
 *
 * @author home
 */
public class ConverterUtil {
    
    private static final Logger log = Logger.getLogger(ConverterUtil.class);
    
    public static Client convertClientSearchToClient(ClientSearchForm search) {
        Client dest = new Client();
        try {
            dest.setFirstname(!StringUtils.isEmpty(search.getFirstname()) ? AppConstants.PERCENT_SYMBOL + search.getFirstname() + AppConstants.PERCENT_SYMBOL:AppConstants.PERCENT_SYMBOL);
            dest.setSurname(!StringUtils.isEmpty(search.getSurname()) ? AppConstants.PERCENT_SYMBOL + search.getSurname() + AppConstants.PERCENT_SYMBOL:AppConstants.PERCENT_SYMBOL);
            dest.setIdno(!StringUtils.isEmpty(search.getIdno()) ? AppConstants.PERCENT_SYMBOL + search.getIdno() + AppConstants.PERCENT_SYMBOL:AppConstants.PERCENT_SYMBOL);
            dest.setStatus(!StringUtils.isEmpty(search.getStatus()) ? search.getStatus():ActiveInactiveType.ACTIVE.get());
            dest.setDob(search.getDob()!=null ? search.getDob():null);
        } catch (Exception ex) {
          log.error(ex);
        }
        return dest;
    }
    
}
